<div class="widfats">
    <!-- Post by Post Term -->
    <div class="widget" id="widget_latest_posts">
        <div class="toggle">&nbsp;</div>
        <h3 class="handle"><?php __('Latest Posts'); ?></h3>
        <div class="content">
            <div class="posts home" id="latest_posts">
                <?php if(count($terms)): ?>
                    <?php App::import('Sanitize'); ?>
                    <?php foreach($terms as $i=>$term): ?>
                        <h3 class="post_term" target="#post_term_<?php e($term['PostTerm']['name']); ?>">
                            <?php e($term['PostTerm']['name']); ?></h3>
                    <?php endforeach; ?>
                    <?php foreach($terms as $i=>$term): ?>
                        <ul class="post_list" id="post_term_<?php e($term['PostTerm']['name']); ?>">
                        <?php if(!empty($term['Post'])): ?>
                            <?php foreach($term['Post'] as $i=>$post): 
                                $class = $post['attachment_count'] > 0 ? ' has_attachment' : '';?>
                                <li class="post_item<?php echo $class; ?>"
                                    title="<?php echo $text->truncate(
                                        Sanitize::stripAll(strip_tags($post['content']))); ?>">
                                    <?php e($html->link(
                                        sprintf('%s(%s)',
                                            $post['title'],
                                            date('Y-m-d', strtotime($post['created']))),
                                        array(
                                            'controller'=>'posts',
                                            'action'=>'view',
                                            $post['id']
                                        )
                                    )); ?>
                                </li>
                            <?php endforeach; ?>
                        <?php else: ?>
                            <li><?php __('No post under this term'); ?></li>
                        <?php endif; ?>
                        </ul>
                    <?php endforeach; ?>
                <?php else: ?>
                    <p><?php __('No post term'); ?></p>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>

<div class="sidebar">
    <!-- Company list by created -->
    <div class="widget" id="widget_latest_companies">
        <div class="toggle">&nbsp;</div>
        <h3 class="handle"><?php __('Latest Companies'); ?></h3>
        <div class="content">
            <div class="companies home" id="latest_companies">
                <?php if(count($companies)): ?>
                    <ul>
                    <?php foreach($companies as $i=>$company): ?>
                        <li title="<?php echo $text->truncate(
                                Sanitize::stripAll(strip_tags($company['Company']['introduction']))); ?>">
                            <?php e($html->link(
                                sprintf('%s(%s)',
                                    $company['Company']['name'],
                                    date('Y-m-d', strtotime($company['Company']['created']))),
                                array('controller'=>'companies','action'=>'view',$company['Company']['id'])
                            )); ?>
                        </li>
                    <?php endforeach; ?>
                    </ul>
                <?php else: ?>
                    <p><?php __('No company'); ?></p>
                <?php endif; ?>
            </div>
        </div>
    </div>
    <!-- Job list by created -->
    <div class="widget" id="widget_latest_jobs">
        <div class="toggle">&nbsp;</div>
        <h3 class="handle"><?php __('Latest Jobs'); ?></h3>
        <div class="content">
            <div class="jobs home" id="latest_jobs">
                <?php if(count($jobs)): ?>
                    <ul>
                    <?php foreach($jobs as $i=>$job): ?>
                        <li title="<?php echo $text->truncate(
                            Sanitize::stripAll(strip_tags($job['Job']['requirement']))); ?>">
                            <?php e($html->link(
                                sprintf('%s(%s)',
                                    $job['Job']['title'],
                                    date('Y-m-d', strtotime($job['Job']['created']))),
                                array('controller'=>'jobs','action'=>'view',$job['Job']['id'])
                            )); ?>
                        </li>
                    <?php endforeach; ?>
                    </ul>
                <?php else: ?>
                    <p><?php __('No job'); ?></p>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>
<!-- bind Job title toggler for job content -->
<script type="text/javascript">
    jQuery(function(){
        var terms = $('h3.post_term'), lists = $('ul.post_list');
        //contents.hide().appendTo($('div.content'));
        terms.click(function(){
            $('ul.post_list:visible').hide();
            $($(this).attr('target')).show();
        });
        $('h3.post_term:first').click();
        $('<br class="clear"/>').insertAfter($('h3.post_term:last'));
        $('#widget_latest_posts').css('min-height', '300px');
    });
</script>

